import os
from PySide6.QtWidgets import QApplication, QDialog, QVBoxLayout
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QFile, QUrl
from pyecharts.charts import Line
from pyecharts.globals import CurrentConfig
import pyecharts.options as opts
CurrentConfig.ONLINE_HOST = 'https://cdn.bootcdn.net/ajax/libs/echarts/5.4.3/'
class ChartApp(QDialog):
   def __init__(self):
       super().__init__()
       self.setWindowTitle("ECharts in PySide6")
       self.setGeometry(100, 100, 800, 600)
       layout = QVBoxLayout()
       self.setLayout(layout)
       # 创建 ECharts 图表
       line = Line()
       line.add_xaxis(["Jan", "Feb", "Mar", "Apr", "May", "Jun"])
       line.add_yaxis("Sales", [5, 20, 36, 10, 75, 90])
       line.set_global_opts(title_opts=opts.TitleOpts(title="Monthly Sales"))
       # 将图表嵌入到 QWebEngineView 中
       web_view = QWebEngineView()
       with open('line.html',mode='w') as f:
          f.write(line.render_embed())
       print(line.render_embed())
       web_view.setHtml(line.render_embed())
       layout.addWidget(web_view)
if __name__ == "__main__":
   app = QApplication([])
   chart_app = ChartApp()
   chart_app.show()
   app.exec()